fix(keychain): keep using a valid connector token when its refresh fails - #644
Open
koreankop wants to merge 1 commit into
Open
fix(keychain): keep using a valid connector token when its refresh fails#644koreankop wants to merge 1 commit into
koreankop wants to merge 1 commit into
Conversation
A refresh runs as soon as a token enters the refresh margin, and its result was returned unconditionally — so one failed refresh handed the turn nothing, even though the stored token typically had minutes of life left. A machine waking with DNS not yet up therefore knocked healthy connectors out for the whole turn: refreshes failed with 'fetch failed', tools got no token, and work whose grant was perfectly fine came back as 401s and 'needs reconnect'. Fall back to the stored token when a refresh fails and the token has not yet reached its expiry skew. The failure is still recorded on the record, so a genuine revocation still surfaces as needs-reconnect the moment the token actually expires — the outage window just stops taking working credentials down with it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A connector token refresh fires as soon as the token enters the refresh margin, and its result is returned unconditionally. One failed refresh therefore hands the turn nothing — even though the stored token usually has minutes of life left and would have worked fine.
That turns a brief network problem into a credential outage. Observed on a machine waking from sleep with DNS not yet up: a run of
[keychain] connector token refresh failed for <host>: fetch failed, tools that then had no token at all, and scheduled work coming back as provider 401s and "needs reconnect" — for grants that were never revoked. Because the orchestrator walks every connector host, a single bad minute takes out the whole set.This change falls back to the stored token when a refresh fails and the token has not yet reached its expiry skew. The failure is still stamped on the record, so a genuine revocation still surfaces as needs-reconnect the moment the token really expires; the outage window just stops taking working credentials down with it.
No retries, no new knobs, no added latency: the fallback path is the one that was already returning
null.Test plan
node --experimental-test-module-mocks --test test/keychain.test.ts— 45/45 pass,tsc --noEmitandeslintclean. Three new cases:refreshFailedAtis recorded, and status does not report needsReconnect (this one fails onmain);Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.